home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvmtest / pvm_test.c < prev    next >
C/C++ Source or Header  |  1997-08-06  |  12KB  |  377 lines

  1. #include "pvm_test.h"
  2. #include "module_list.h"
  3.  
  4.  
  5. main(argc,argv)
  6. int    argc;
  7. char  **argv;
  8. {
  9. char    myversion[25];
  10. char    *myarch;
  11. char    myhostname[MAX_HOST_NAME_LENGTH];
  12. int    test_num;                /* Current test module processed         */
  13. int    num_hosts=1;                /* Number of hosts (not including this one)     */
  14. FILE    *infile = NULL;                /* input file                     */
  15. char    outfilename[OUTFILE_MAX_LENGTH];    /* Name of output file                */
  16. int    mytid;                    /* PVM tid                    */
  17. int    num_diff_arch;                /* Number of different data format        */
  18. int    shuffle[MAX_HOST];            /* Array of shuffled index of hostpool        */
  19. int    sub_shuffle_pool[MAX_HOST];        /* Subset of shuffle                 */
  20. int     i,j,k;                    /* Loop indices                    */
  21. int     req;                    /* Num of hosts required for the current test    */
  22. int    num_wanted;                /* Number of hosts wanted after a test        */
  23. int    num_wanted_ef;                /* Actual number of hosts wanted        */
  24. int    status;                    /* Temporary status of a test            */
  25. int    index;                    /* Size of window in shuffle            */
  26. int    info;                    /* Dummy variable to keep track of return values*/
  27. char    name1[25];                /* Name of the output file for test 45        */
  28. char     name2[25];                /* Name of the output file for test 46        */
  29. extern void term();                /* Interruption handler             */
  30.  
  31.  
  32.  
  33. /************************************************/
  34. /*    Miscelleanous Initialisation              */
  35. /************************************************/
  36.  
  37. /*****    Set stdout and stderr        *****/
  38.  
  39. dup2(fileno(stdout),2);
  40. setbuf(stdout,NULL);
  41.  
  42. /*****  Parse the arguments         *****/
  43. if (argc != 2)
  44.         {
  45.         fprintf(stderr,"Usage: %s <input file> \n",argv[0]);
  46.         exit(1);
  47.         }
  48.  
  49. /*****    Get PVM_ARCH            *****/
  50. if((myarch = getenv("PVM_ARCH"))== NULL)
  51.     {
  52.     fprintf(stderr,"\tThe PVM_ARCH environment variable should be set \n");
  53.     exit(1);
  54.     }
  55.  
  56. /***** Get name of this host            *****/
  57. if (gethostname(myhostname,MAX_HOST_NAME_LENGTH) == -1)
  58.         {
  59.         fprintf(stderr,"\tgethostname() call failed");
  60.         exit(1);
  61.         }
  62.  
  63. /***** Get version of PVM on this host *****/
  64. if (pvm_version() == NULL)
  65.     {
  66.     fprintf(stderr,"\tpvm_version() : Failed\n");
  67.     exit(1);
  68.     }
  69.     
  70. strcpy(myversion,pvm_version());
  71.  
  72.  
  73. strcpy(hostpool[0]=(char*)malloc(sizeof(char)*strlen(myhostname)+1),myhostname);
  74. strcpy(hostarch[0]=(char*)malloc(sizeof(char)*strlen(myarch)+1),myarch);
  75.  
  76. /***** Test structure initialisation     *****/
  77.     masters = (module_array *)module_list;
  78.  
  79. /***** Setting the default parameters   *****/
  80.  
  81. messages_length     = MESSAGES_LENGTH_DEFAULT;
  82. max_size         = MAX_SIZE_DEFAULT;
  83. incr             = INCR_DEFAULT;
  84. start_size         = START_SIZE_DEFAULT;
  85. num_messages         = NUM_MESSAGES_DEFAULT;
  86. all_combos         = ALL_COMBOS_DEFAULT; 
  87. timing_average        = TIMING_AVERAGE_DEFAULT;
  88. timing_total        = TIMING_TOTAL_DEFAULT;
  89.  
  90. all_tests        = ALL_TESTS_DEFAULT;
  91. all_messaging        = ALL_MESSAGING_DEFAULT;
  92. all_routine        = ALL_ROUTINE_DEFAULT;
  93. all_funnel_nodata    = ALL_FUNNEL_NODATA_DEFAULT;
  94. all_funnel_data        = ALL_FUNNEL_DATA_DEFAULT;
  95. all_head_nodata        = ALL_HEAD_NODATA_DEFAULT;
  96. all_head_data        = ALL_HEAD_DATA_DEFAULT;
  97. all_triangle_nodata    = ALL_TRIANGLE_NODATA_DEFAULT;
  98. all_triangle_data    = ALL_TRIANGLE_DATA_DEFAULT;
  99. all_perf        = ALL_PERF_DEFAULT;
  100.  
  101. /***** Input file parsing         *****/
  102. input_parse(infile,argv[1],&num_hosts,myhostname,outfilename);
  103.  
  104. /***** Welcome message  *****/
  105.  
  106. fprintf(outfile,"------------------------------------\n");
  107. fprintf(outfile,"PVM tester --- version 2.0\n");
  108. fprintf(outfile,"------------------------------------\n");
  109.  
  110. /***** check Parameters *****/
  111.  
  112. if (start_size > max_size)
  113.     {
  114.     start_size = max_size;
  115.     fprintf(stdout,"\t Warning : Minimum size > Maximum size\n");
  116.     }
  117.  
  118. /***** Update Tests Setting        *****/
  119.  
  120. if (all_tests == 1)
  121.     for (i=0;i<NUMBER_OF_TESTS;i++)
  122.         (*masters)[i].flag.perform = 1;
  123. if (all_messaging == 1)
  124.     for (i=47;i<NUMBER_OF_TESTS;i++)
  125.         (*masters)[i].flag.perform = 1;
  126. if (all_routine == 1)
  127.     {
  128.     for (i=0;i<44;i++)
  129.         (*masters)[i].flag.perform = 1;
  130.     (*masters)[46].flag.perform = 1;
  131.     }
  132. if (all_funnel_nodata == 1)
  133.     for (i=79;i<93;i++)
  134.         (*masters)[i].flag.perform = 1;
  135. if (all_funnel_data == 1)
  136.     for (i=93;i<NUMBER_OF_TESTS;i++)
  137.         (*masters)[i].flag.perform = 1;
  138. if (all_head_nodata == 1)
  139.     for (i=47;i<55;i++)
  140.         (*masters)[i].flag.perform = 1;
  141. if (all_head_data == 1)
  142.     for (i=55;i<63;i++)
  143.         (*masters)[i].flag.perform = 1;
  144. if (all_triangle_nodata == 1)
  145.     for (i=63;i<71;i++)
  146.         (*masters)[i].flag.perform = 1;
  147. if (all_triangle_data == 1)
  148.     for (i=71;i<79;i++)
  149.         (*masters)[i].flag.perform = 1;
  150. if (all_perf == 1)
  151.     {
  152.     (*masters)[44].flag.perform = 1;
  153.     (*masters)[45].flag.perform = 1;
  154.     }
  155.  
  156. /***** Possible output files        *****/
  157. if ((*masters)[44].flag.perform == 1)
  158.         {
  159.      if (outfile == stdout)
  160.         {
  161.             sprintf(name1,"%s.%d",OUT45,getpid());
  162.                 if ((out45=fopen(name1,"w"))==NULL)
  163.                         {
  164.                     fprintf(stderr,"\tfopen() Failed to open %s\n",OUT45);
  165.                     exit(1);
  166.                     }
  167.         }
  168.     else
  169.         out45 = outfile;
  170.         }
  171. if ((*masters)[45].flag.perform == 1)
  172.         {
  173.     if (outfile == stdout)
  174.         {
  175.             sprintf(name2,"%s.%d",OUT46,getpid());
  176.             if ((out46=fopen(name2,"w"))==NULL)
  177.                     {
  178.                     fprintf(stderr,"\tfopen() Failed to open %s\n",OUT46);
  179.                     exit(1);
  180.                     }
  181.         }
  182.     else
  183.         out46 = outfile;
  184.         }
  185.  
  186. /***** Set handlers             *****/
  187. signal(SIGINT,term);
  188. signal(SIGTERM,term);
  189.  
  190. /***** Compute my tid             *****/
  191. if ((mytid = pvm_mytid())<0)
  192.     {
  193.     fprintf(outfile,"\tCannot contact local demon \n");
  194.     term(HIGH_LEVEL);
  195.     }
  196. /***** Disable pvm error messages       *****/
  197. info = pvm_setopt(PvmAutoErr,0);
  198. if (info <0)
  199.         {
  200.         fprintf(outfile,"\tpvm_setopt() : Failed with error %d\n",info);
  201.         fprintf(outfile,"\tSome extra messages will appear\n");
  202.         }
  203.  
  204. /***** Start Group Server        *****/
  205. if (start_group_server() == -1)
  206.     term (HIGH_LEVEL);
  207.  
  208. /***** Check hosts             *****/
  209. if (check_hosts(num_hosts) == -1)
  210.     term(HIGH_LEVEL);
  211.  
  212. /***** Check Version             *****/
  213. info = check_version(num_hosts,myversion);
  214. if (info == -1)
  215.     term(HIGH_LEVEL);
  216. /***** Get all arch            *****/
  217. if (get_all_arch() == -1)
  218.     term(HIGH_LEVEL);
  219. /***** Get number of different arch    *****/
  220. if ((num_diff_arch = get_num_diff_arch(num_hosts)) <0)
  221.     {
  222.     fprintf(outfile,"\tUnable to compute the number of different architeccture\n");
  223.     term(HIGH_LEVEL);
  224.     }
  225. /***** Compute the shuffle        *****/
  226. if (find_shuffle(num_hosts,num_diff_arch,shuffle) <0)
  227.     {
  228.     fprintf(outfile,"\tUnable to compute the shuffle\n");
  229.     exit(1);
  230.     }
  231. /***** Remove all hosts         *****/
  232. if (remove_all_hosts() == -1)
  233.     term(HIGH_LEVEL);
  234. /***** Printout Configuration         *****/
  235. print_out_misc(myversion,num_hosts,argv[1],outfilename);
  236.  
  237. /************************************************/
  238. /*         Main loop                   */
  239. /************************************************/
  240. for (test_num=0;test_num< NUMBER_OF_TESTS;test_num++)
  241.     {
  242.     if ((*masters)[test_num].flag.perform == 1)
  243.         {    /*    We perform this test        */
  244.         fprintf(outfile,"test#%d: %s\n",test_num+1,(*masters)[test_num].description);
  245.         req = (*masters)[test_num].num_req_hosts;
  246.         num_wanted = (*masters)[test_num].flag.after_hosts;
  247.         if (req == ALL_HOSTS)
  248.             req = num_hosts;
  249.         if (req == ALL_ARCHS)
  250.             req = num_diff_arch+1;
  251.         if (req >num_hosts)
  252.             req = num_hosts;
  253.         if (num_wanted == ALL_HOSTS)
  254.                         num_wanted = num_hosts;
  255.                 if (num_wanted == ALL_ARCHS)
  256.                         num_wanted = num_diff_arch+1;
  257.                 if (num_wanted >num_hosts)
  258.                         num_wanted = num_hosts;
  259.         if ((req > num_diff_arch)||(req == 1)||(req>=num_hosts)||(all_combos == 0))
  260.             /****** No shuffling Problems ******/
  261.  
  262.             {
  263.             if (allocate(shuffle,req,&num_wanted) <0)
  264.                 {    /* The allocation didn't succeed    */
  265.                 fprintf(outfile,"\tAllocation failed for some hosts\n");
  266.                 (*masters)[test_num].status = NOT_COMPLETED;
  267.                 if (remove_all_hosts() <0)
  268.                     {       /* Cannot remove hosts  */
  269.                     fprintf(outfile,"\tCannot delete hosts\n");
  270.                     term(HIGH_LEVEL);
  271.                     }    
  272.                 }
  273.             else        /* We do the test */
  274.                 {
  275.                 status = (*masters)[test_num].proc_master(shuffle,req);
  276.                 if (status == NOT_POSSIBLE)
  277.                     {
  278.                     (*masters)[test_num].status=PASSED;
  279.                     fprintf(outfile,"\tNot_possible for architecture combination :\n");
  280.                     fprintf(outfile,"\t%s |  ",myarch);
  281.                     for (k=1;k<req;k++)
  282.                         fprintf(outfile," %s ",hostarch[shuffle[k]]);
  283.                     for (k=req;k<(*masters)[test_num].num_req_hosts;k++)
  284.                         fprintf(outfile," %s ",hostarch[shuffle[k%req]]);
  285.                     fprintf(outfile,"\n");
  286.                     }
  287.                 if(status == PASSED)
  288.                     (*masters)[test_num].status=PASSED;
  289.                 if (status == FAILED)
  290.                     (*masters)[test_num].status=FAILED;    
  291.                 if ((info = unexpected_host_killed(num_wanted-1)) == -1)
  292.                     {
  293.                     fprintf(outfile,"\tNot the right number of hosts after this test\n");
  294.                     (*masters)[test_num].status = NOT_COMPLETED;
  295.                     }    
  296.                 if (info == -2)
  297.                     {
  298.                     fprintf(outfile,"\tFailure of checking function\n");
  299.                     (*masters)[test_num].status = NOT_COMPLETED;
  300.                     }    
  301.                 if (remove_all_hosts() <0)
  302.                                     {       /* Cannot remove hosts  */
  303.                                     fprintf(outfile,"\tCannot delete hosts\n");
  304.                                     term(HIGH_LEVEL);
  305.                                     }
  306.                 print_test_result(test_num);
  307.                 }
  308.             }
  309.         else
  310.             /***** We must try all the combinations *****/
  311.             {
  312.             sub_shuffle_pool[0]=shuffle[0];
  313.             (*masters)[test_num].status = PASSED;
  314.             for (i=0;i<num_diff_arch-req+2;i++)
  315.                 {
  316.                 sub_shuffle_pool[1]=shuffle[i+1];
  317.                 if (req==2)
  318.                     index = 1;
  319.                 else
  320.                     index = num_diff_arch-req-i+2;
  321.                 for (j=0;j<index;j++)
  322.                     {
  323.                     num_wanted_ef = num_wanted;
  324.                     for(k=1;k<req-1;k++)
  325.                         sub_shuffle_pool[k+1] = shuffle[i+j+k+1];
  326.                     if (allocate(sub_shuffle_pool,req,&num_wanted_ef) <0)
  327.                         {    /* The allocation didn't succeed        */
  328.                         fprintf(outfile,"\tAllocation failed for some hosts\n");
  329.                                         (*masters)[test_num].status = NOT_COMPLETED;    
  330.                         if (remove_all_hosts() < 0)
  331.                             {/*     Cannot remove hosts    */
  332.                             fprintf(outfile,"\tCannot remove hosts\n");
  333.                             term(HIGH_LEVEL);
  334.                             }
  335.                         }
  336.                     else    /* We do the test    */
  337.                         {
  338.                         status = (*masters)[test_num].proc_master(sub_shuffle_pool,req);
  339.                         if (status == FAILED)
  340.                             {
  341.                             (*masters)[test_num].status = FAILED;
  342.                             fprintf(outfile,"\tFailed for architecture combination : ");
  343.                             fprintf(outfile,"\t%s ",myarch);
  344.                             for (k=1;k<req;k++)    
  345.                                 fprintf(outfile," %s ",hostarch[sub_shuffle_pool[k]]);
  346.                             fprintf(outfile,"\n");
  347.                             }    
  348.                         if (status == NOT_POSSIBLE)
  349.                             {
  350.                             fprintf(outfile,"\tNot_possible for architecture combination :");
  351.                             fprintf(outfile,"%s | ",myarch);
  352.                             for (k=1;k<req;k++)
  353.                                 fprintf(outfile," %s ",hostarch[sub_shuffle_pool[k]]);
  354.                             for (k=req;k<(*masters)[test_num].num_req_hosts;k++)
  355.                                 fprintf(outfile," %s ",myarch);
  356.                             fprintf(outfile,"\n");
  357.                             }    
  358.                         if (unexpected_host_killed(num_wanted_ef-1) <0 )
  359.                             {
  360.                                                 fprintf(outfile,"\tSome hosts has unexpectedly died\n");
  361.                                                 (*masters)[test_num].status = FAILED;
  362.                                                 }
  363.                         if (remove_all_hosts() <0)
  364.                                                 {       /* Cannot remove hosts  */
  365.                                                 fprintf(outfile,"\tCannot delete hosts \n");
  366.                                                 term(HIGH_LEVEL);
  367.                                                 }
  368.                         }
  369.                     }
  370.                 }        
  371.             print_test_result(test_num);
  372.             }    
  373.         }
  374.     }
  375. term(OK_LEVEL);
  376. }
  377.